package chapter4;
// 定义Animal类
class Animal1 {
    private String name;
    private int age;
    public Animal1 (String name, int age) {
        this.name = name;
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String info(){
        return "名称: " + this.getName() + " 年龄: " + this.getAge();
    }
}
// 定义Dog类继承Animal类
class Dog1 extends Animal1 {
    private String color;
    public Dog1 (String name, int age, String color) {
        super(name, age);
        this.setColor (color);
    }
    public String getColor() {
        return color;
    }
    public void setColor (String color) {
        this.color = color;
    }
    // 重写父类的info()方法
    public String info(){
        return super.info()+",颜色: " + this.getColor();// 扩充父类中的方法
    }
}
// 定义测试类
public class Example06 {
    public static void main(String[] args) {
        Dog1 dog1 = new Dog1("牧羊犬",3,"黑色");// 创建Dog1类实例对象
        System.out.println(dog1.info());
    }
}
